// 64 =

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
constexpr int MaxN = 2e5 + 5;
int n;
int a[MaxN];
int b[MaxN];
int answer[MaxN];
std::set<std::tuple<int, int>> set;
std::priority_queue<std::tuple<int, int>, std::vector<std::tuple<int, int>>, std::greater<>> points;
std::priority_queue<std::tuple<int, int>, std::vector<std::tuple<int, int>>, std::greater<>> queueA;
std::priority_queue<std::tuple<int, int>, std::vector<std::tuple<int, int>>, std::greater<>> queueB;
int main()
{
    freopen("min.in", "r", stdin);
    freopen("min.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    bool sameB = true;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &b[i]);
    }
    for (int i = 2; i <= n; i++)
    {
        sameB &= b[i] == b[i - 1];
    }
    if (sameB)
    {
        if (b[1] == 1)
        {
            int best = 0x3f3f'3f3f;
            for (int i = 1; i <= n; i++)
            {
                best = std::min(best, a[i]);
            }
            for (int i = 1; i <= n; i++)
            {
                printf("%d\n", best - 1);
            }
        }
        else if (b[1] == 1e9)
        {
            for (int i = 1; i <= n; i++)
            {
                answer[i] = 0x7f7f'7f7f;
                points.push({a[i], i});
            }
            set.insert({1, n});
            for (; !points.empty();)
            {
                int x, w;
                std::tie(x, w) = points.top();
                points.pop();
                auto it = set.upper_bound({w, 0x7f7f'7f7f});
                it--;
                int l, r;
                std::tie(l, r) = *it;
                answer[r - l + 1] = std::min(answer[r - l + 1], abs(x - int(1e9)));
                set.erase(it);
                if (l != w)
                {
                    set.insert({l, w - 1});
                }
                if (r != w)
                {
                    set.insert({w + 1, r});
                }
            }
            int best = 0x7f7f'7f7f;
            for (int i = n; i >= 1; i--)
            {
                answer[i] = std::min(answer[i], best);
                best = std::min(best, answer[i]);
            }
            for (int i = 1; i <= n; i++)
            {
                printf("%d\n", answer[i]);
            }
        }
        return 0;
    }
    for (int len = 1; len <= n; len++)
    {
        for (; !queueA.empty();)
        {
            queueA.pop();
        }
        for (; !queueB.empty();)
        {
            queueB.pop();
        }
        for (int i = 1; i <= len; i++)
        {
            queueA.push({a[i], i});
            queueB.push({b[i], i});
        }
        int answer = abs(std::get<0>(queueA.top()) - std::get<0>(queueB.top()));
        for (int i = len + 1; i <= n; i++)
        {
            queueA.push({a[i], i});
            queueB.push({b[i], i});
            for (; std::get<1>(queueA.top()) <= i - len;)
            {
                queueA.pop();
            }
            for (; std::get<1>(queueB.top()) <= i - len;)
            {
                queueB.pop();
            }
            answer = std::min(answer, abs(std::get<0>(queueA.top()) - std::get<0>(queueB.top())));
        }
        printf("%d\n", answer);
    }
    return 0;
}
